<?php

namespace App\Model;

use EasySwoole\ORM\AbstractModel;
use EasySwoole\ORM\Db\Cursor;
use EasySwoole\ORM\Db\CursorInterface;
use EasySwoole\ORM\Exception\Exception;
use Throwable;

/**
 * Class UserWechatOpenModel
 * Create With Automatic Generator
 * @property $id
 * @property $openid
 * @property $unionid
 * @property $type
 * @property $create_time
 */
class UserWechatOpenModel extends AbstractModel
{
    protected $tableName = 'bee_user_wechat_open';

    protected $primaryKey = 'id';

    protected $autoTimeStamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = false;

    /**
     * 添加到微信体系
     * @param string $openId
     * @param string $unionId
     * @param int $type
     * @return UserWechatOpenModel|array|bool|AbstractModel|Cursor|CursorInterface|null
     * @throws \EasySwoole\Mysqli\Exception\Exception
     * @throws Exception
     * @throws Throwable
     */
    public function addUserWechatOpen(string $openId, string $unionId, int $type)
    {
        $res = $this->data([
            'openid' => $openId,
            'unionid' => $unionId,
            'type' => $type,
            'create_time' => time(),
        ], false)->save();

        return $this->get($res);
    }
}